﻿using System;

namespace SortingNetworkSimulator.Model
{
    public class Comparator
    {
        public int WireOneIndex { get; private set; }
        public int WireTwoIndex { get; private set; }
        public int LayerIndex { get; set; }
        public int DrawingLayerIndex { get; set; }

        public Comparator(int wireOneIndex, int wireTwoIndex, int layerIndex, int drawingLayerIndex)
        {
            if (wireOneIndex >= wireTwoIndex)
            {
                throw new ArgumentException("wireOneIndex must be less than wireTwoIndex");
            }

            this.WireOneIndex = wireOneIndex;
            this.WireTwoIndex = wireTwoIndex;
            this.LayerIndex = layerIndex;
            this.DrawingLayerIndex = drawingLayerIndex;
        }

        public void Compare(double[] networkInput)
        {
            double tmp;

            if (networkInput[WireOneIndex] > networkInput[WireTwoIndex])
            {
                tmp = networkInput[WireOneIndex];
                networkInput[WireOneIndex] = networkInput[WireTwoIndex];
                networkInput[WireTwoIndex] = tmp;
            }
        }
    }
}
